package com.dz.sideoutput;

import com.dz.operator.MyProcess;
import com.dz.outputag.NumberOutTagEnum;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import org.apache.flink.util.OutputTag;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName SideoutPutdemo2
 * @Description TODO
 * @Author zhangdong
 * @Date 2020/10/18 12:42
 * @Version 1.0
 */
public class SideoutPutdemo2
{
    public static final OutputTag<String> rejectedWordsTag = new OutputTag<String>("unicom1"){};

    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment en = StreamExecutionEnvironment.createLocalEnvironment();

        DataStream<String> dataStream =    en.fromElements("15662287964",
                "17663722761",
                "18199525365",
                "15875887346",
                "18640328321",
                "17170824689",
                "15983307247",
                "13983612448",
                "17309953705",
                "19803568860",
                "18315737994",
                "15538648859",
                "18877652418",
                "17846407504",
                "18764936916",
                "15083288614",
                "18388044960",
                "15644557264",
                "15551368480",
                "18651668495",
                "17325289253",
                "18474657459",
                "17608538126",
                "15261533537",
                "15858515381",
                "18257647080",
                "17633974642",
                "13215407322",
                "18783547925",
                "13973065227",
                "13613134851",
                "18287072997",
                "15537501364",
                "13760854701",
                "13762584544",
                "15347287321",
                "19812286896",
                "18551382577",
                "13735777559",
                "18063372996",
                "15667109931",
                "18812121406",
                "15091925082",
                "17519604080",
                "17193638028",
                "18850036649",
                "13671058828",
                "15677347219",
                "15574513875",
                "17834682853",
                "18330999147",
                "17781897619",
                "13404793115",
                "15996037083",
                "17697313410",
                "18003439059",
                "18417294053",
                "13981271500",
                "15707285688",
                "18157721706",
                "13312795988",
                "13419492191",
                "18328505483",
                "18161907632",
                "17685509457",
                "18878064618",
                "18991132682",
                "18511249967",
                "13121456257",
                "18494792996",
                "19940578449",
                "17309399901",
                "15567283196",
                "15342067684",
                "13061066277",
                "17641937213",
                "15155125088",
                "18764693925",
                "15248964590",
                "18271595009",
                "13417812471",
                "19883366826",
                "18490942302",
                "15170794691",
                "19809372009",
                "18358467585",
                "15141496776",
                "15241412600",
                "15163022495",
                "13517766690",
                "18522734053",
                "17368431789",
                "13822094960",
                "15602658445",
                "17523472107",
                "15814487444",
                "15699517383",
                "17131976880",
                "13222482275",
                "17685254304",
                "13784795455",
                "18463143185",
                "19811921887",
                "16628797610",
                "18900942683",
                "17615203251",
                "15341345686",
                "18237648471",
                "18802531107",
                "15325154285",
                "13815179591",
                "13214654757",
                "18223589603",
                "14708524491",
                "13743293688",
                "13200155246",
                "15714503791",
                "17332195372",
                "18682407958",
                "18534575098",
                "18999021477",
                "15088968900",
                "13313944151",
                "18118252039",
                "15882183150",
                "17518323044",
                "13647984222",
                "13640863807",
                "15574676609",
                "13505847450",
                "15176225314",
                "13396832790",
                "18168884910",
                "18962874191",
                "18688537659",
                "18349684751",
                "13497314038",
                "13111749739",
                "17570563194",
                "15820076591",
                "18448904562",
                "15896905435",
                "18978986318",
                "15987315699",
                "15042406247",
                "17822397895",
                "18871053902",
                "19973516925",
                "17662745989",
                "17228745760",
                "17649051465",
                "13855821073",
                "19916854266",
                "18205445061",
                "13594403004",
                "13775668017",
                "13402553009",
                "13149948423",
                "14526415792",
                "18061019282",
                "13256747621",
                "15958383802",
                "18058438624",
                "17617088005",
                "18445743135",
                "13211726277",
                "18165749594",
                "13845985688",
                "18246348015",
                "18331781468",
                "17704395312",
                "13343625373",
                "15934355677",
                "18202246712",
                "17765591386",
                "13663175235",
                "15736263598",
                "17129429533",
                "17216696352",
                "17606024139",
                "19846531733",
                "18920341120",
                "14598052736",
                "13647393169",
                "19883042583",
                "13774176731",
                "17382884783",
                "15863902351",
                "16503677276",
                "17512547745",
                "19924809130",
                "13945927702",
                "14918275309",
                "17841551598",
                "18620049136",
                "18737233614",
                "13946331695",
                "13084915629",
                "14532595228",
                "14703004047",
                "15866452488",
                "16535396204",
                "18356832097",
                "19812313301",
                "18886592586",
                "13448081065",
                "15984426809",
                "15672689865",
                "13529516527",
                "15639658585",
                "15533968085",
                "13206438766",
                "17201769394",
                "15532999418",
                "15875367720",
                "14743681855",
                "13564519880",
                "13112442791",
                "17622117187",
                "18128797036",
                "18276636069",
                "13895318275",
                "15824773675",
                "15053145019",
                "13306369449",
                "13749672825",
                "13875706757",
                "17787023296",
                "14756592400",
                "18498959059",
                "14588833700",
                "18171946674",
                "19826403587",
                "18666064219",
                "17888746022",
                "15769677371",
                "13768016973",
                "13750535630",
                "17834152046",
                "17730444502",
                "19949312858",
                "13652917600",
                "13650178780",
                "18178153839",
                "15032415062",
                "15890814009",
                "15901311567",
                "13836455752",
                "18283948385",
                "13326462049",
                "13182796756",
                "15826763858",
                "13000483794",
                "18282611202",
                "18332686895",
                "17722122644",
                "14574904007",
                "17561238876",
                "17310052389",
                "18180277447",
                "18592488377",
                "13561546486",
                "15158978143",
                "18882141721",
                "14769024596",
                "13433638670",
                "18392626155",
                "13828987178",
                "13521482315",
                "14742629745",
                "19855461350",
                "15908612990",
                "18820762599",
                "18104517446",
                "13935635961",
                "15341667895",
                "19931598101",
                "13809397394",
                "18767345692",
                "15303333817",
                "17754921665",
                "18930719725",
                "17319728134",
                "13618547357",
                "13889132843",
                "18750806443",
                "13557128111",
                "13798975429",
                "15221159919",
                "15562548980",
                "17123442449",
                "15583219521",
                "17323214059",
                "18489168203",
                "15745259007",
                "13578886143",
                "18198131806",
                "17514105955",
                "17361128019",
                "17249083504",
                "13380515244",
                "17863354911",
                "15386542501",
                "13879663884",
                "13342685776",
                "18006187469",
                "17231467341",
                "17860358706",
                "18036788966",
                "17542212353",
                "15512916604",
                "17690766787",
                "18623851292",
                "17760353824",
                "13437611695",
                "14524991185",
                "14783913572",
                "13767959541",
                "13492701205",
                "15192063786",
                "15185642553",
                "15640385320",
                "17621494243",
                "17114226128",
                "15894966610",
                "18914791597",
                "18174025525",
                "15533874207",
                "19899845290",
                "15211347153",
                "15588478110",
                "17520437680",
                "17843567003",
                "15340265533",
                "15524925281",
                "15986259457",
                "13354845658",
                "13485117702",
                "17264137056",
                "16635473556",
                "18810513462",
                "19927582483",
                "17709345429",
                "13550685749",
                "13872751165",
                "13541967823",
                "18442356311",
                "17159947914",
                "17503733509",
                "14594456382",
                "17887796459",
                "17350682548",
                "18187455948",
                "15233595833",
                "13948909847",
                "15618891077",
                "13594726995",
                "17749992670",
                "15090034096",
                "18092464140",
                "18407205441",
                "13996141664",
                "18278256466",
                "13877491320",
                "17681563052",
                "13619112131",
                "15810867461",
                "13864568792",
                "15227228721",
                "15372359595",
                "17620676508",
                "19893975470",
                "18057207149",
                "15061935250",
                "18910779331",
                "13411418688",
                "15113575866",
                "13933925766",
                "15714758539",
                "13789219540",
                "18856387635",
                "18013583606",
                "14521615762",
                "15508417382",
                "13244135781",
                "14740401289",
                "19962492968",
                "18596488878",
                "14543997457",
                "19920079540",
                "17235658241",
                "15100804411",
                "15991046675",
                "15612222974",
                "18503635999",
                "18387898860",
                "13243989802",
                "14513571858",
                "17539423324",
                "15643346289",
                "15502368528",
                "19970682135",
                "13940054607",
                "16525246351",
                "17840484824",
                "18183512953",
                "13957608682",
                "15842517730",
                "18113185141",
                "15626357385",
                "18952783010",
                "13758123751",
                "14712051373",
                "17185545590",
                "16631226637",
                "18938006270",
                "13237879915",
                "15908453978",
                "17242272572",
                "18340426492",
                "13552329150",
                "18154055323",
                "15761541882",
                "16655069788",
                "18549028022",
                "13325357980",
                "13621975000",
                "18224325721",
                "18019091778",
                "19870182319",
                "15342555730",
                "13061807258",
                "13018049656",
                "15836896048",
                "15019257963",
                "14731447214",
                "15710067931",
                "13727781399",
                "17628437312",
                "18919512643",
                "17269659085",
                "18762098892",
                "18168238125",
                "13065743325",
                "19843373698",
                "15711741239",
                "15214564749",
                "13290113871",
                "13461895188",
                "19917506980",
                "18693875695",
                "15393642240",
                "15628719677",
                "13618601417",
                "13207447022",
                "13855896636",
                "14535299905",
                "15994284988",
                "16538599553",
                "18767109656",
                "18475214719",
                "15331449091",
                "14507997929",
                "15584687631",
                "14779132472",
                "13339773720",
                "17691757839",
                "18748626133",
                "15755301240",
                "13120414458",
                "17334984708",
                "18451633013",
                "13923125273",
                "15835005166",
                "13278175837",
                "15055666225",
                "19844626918",
                "13565027765",
                "15608038821",
                "15025114454",
                "17124672281",
                "15751188792",
                "15382942066",
                "13183389715",
                "19989453405",
                "15837682784",
                "13953562148",
                "17729813952",
                "18322048934",
                "18683175270",
                "18737767325",
                "13206739804",
                "15802327881",
                "13476765905",
                "15332202588",
                "14929744438",
                "13577276697",
                "13135525290",
                "15910131266",
                "17134133145",
                "17567996682",
                "15297908813",
                "18608317050",
                "13019613120",
                "18637085183",
                "19845603346",
                "15313433601",
                "15668156499",
                "17802253681",
                "18987217744",
                "14530734291",
                "16567503035",
                "15354122812",
                "14578283880",
                "14740398850",
                "17860598963",
                "13297371336",
                "15356522507",
                "13973616406",
                "13164515165",
                "18234802828",
                "19953483724",
                "15116492218",
                "15726317392",
                "13220233827",
                "18507828166",
                "15171902013",
                "17335256260",
                "13089785630",
                "13036609213",
                "19924171852",
                "15210356759",
                "17595928140",
                "15931723520",
                "14766107230",
                "18359319577",
                "13886759968",
                "18968299511",
                "18701091886",
                "13417406659",
                "14909255748",
                "17673747170",
                "17696882216",
                "15582364177",
                "18268043887",
                "14508934962",
                "14562026868",
                "19997497465",
                "13011963000",
                "13987596559",
                "15980809445",
                "17103958019",
                "18111414918",
                "15626752240",
                "18118824200",
                "15946743318",
                "17668101455",
                "14572772358",
                "18675796657",
                "17104673017",
                "15882434537",
                "15083689025",
                "18204229641",
                "13104694854",
                "17157524761",
                "15983506035",
                "13667275248",
                "17715998812",
                "18035276336",
                "18784338437",
                "17828502181",
                "13469688591",
                "15749222933",
                "15359584218",
                "15817587387",
                "13646246914",
                "17538515273",
                "13067347100",
                "15835785982",
                "13388768085",
                "18504679983",
                "13958509938",
                "16621454941",
                "16555162639",
                "17346671865",
                "18485635881",
                "13091475192",
                "15150805354",
                "15939952772",
                "15680469801",
                "15727526305",
                "15952199715",
                "18643268883",
                "13429031420",
                "18215012300",
                "18945533794",
                "18249133065",
                "19861981039",
                "13229416419",
                "18588028227",
                "15541908172",
                "14580854398",
                "17852678778",
                "13345732972",
                "18855222128",
                "15317288312",
                "16685832963",
                "17378218949",
                "13091114099",
                "17200555924",
                "13486863561",
                "15985764507",
                "16561236282",
                "17853965790",
                "18751095367",
                "13359203183",
                "15802518002",
                "13752876315",
                "18715531663",
                "16518416759",
                "13541373423",
                "18368385226",
                "15633846442",
                "15878877659",
                "18987719929",
                "15558244236",
                "16623064294",
                "15839135523",
                "17826655037",
                "17658888111",
                "18302181593",
                "15120155627",
                "18255183632",
                "15797576746",
                "13771824765",
                "19863497411",
                "15836545716",
                "13500474813",
                "15207367654",
                "18041024946",
                "15648175745",
                "15540196757",
                "18653661253",
                "15752362845",
                "15709822143",
                "13765659254",
                "15679981331",
                "17187534760",
                "16511891819",
                "18108925842",
                "15077439869",
                "15087138568",
                "15572029386",
                "13780523628",
                "13681352642",
                "13356653399",
                "18316363613",
                "18557069916",
                "18086889890",
                "18117085694",
                "13753532339",
                "18718965178",
                "17178776160",
                "18484197068",
                "17603866613",
                "18736804034",
                "18942764971",
                "14723587487",
                "13225744472",
                "13223823474",
                "15245302161",
                "15229762273",
                "15057934747",
                "15389931262",
                "17397268409",
                "13204908997",
                "14780259741",
                "14533993081",
                "14770638053",
                "18785559980",
                "17398559049",
                "15193499909",
                "17624854995",
                "15632831664",
                "18009756559",
                "15203092701",
                "17321272364",
                "17620974600",
                "14529734398",
                "19809752472",
                "15194662426",
                "17151307956",
                "13184687943",
                "19850539260",
                "13864557836",
                "13180863584",
                "17584851458",
                "13768146743",
                "15389899587",
                "15553779384",
                "13466418266",
                "13276671949",
                "14757574822",
                "18894393560",
                "18472491005",
                "17187435752",
                "15674883760",
                "18443854359",
                "16671268803",
                "13541606732",
                "18914513097",
                "17761488609",
                "17712928887",
                "13986743902",
                "13760637766",
                "19818277571",
                "13738339695",
                "13535761425",
                "19833076081",
                "13145043325",
                "18380929670",
                "18819427993",
                "13710497616",
                "17635308715",
                "17643813545",
                "19944641692",
                "18049519487",
                "18781297604",
                "14782594418",
                "17529936575",
                "17806807358",
                "15578065030",
                "17764844346",
                "19862544512",
                "18215692141",
                "14783489546",
                "13747064758",
                "13448923768",
                "13611748863",
                "15158776694",
                "19951197288",
                "15547943270",
                "18388837925",
                "19842251556",
                "15647979853",
                "15288203424",
                "13814738656",
                "18553547410",
                "15548559078",
                "15764022685",
                "16602952063",
                "18112789717",
                "15292076433",
                "13490162831",
                "17198045474",
                "17684319212",
                "18818575258",
                "18726654948",
                "15913634384",
                "17628343418",
                "18374317246",
                "18180205517",
                "15337688600",
                "15804313482",
                "18767029698",
                "19980866624",
                "17589966502",
                "15606453235",
                "19835185439",
                "17161455987",
                "18120659026",
                "18356305832",
                "15829062624",
                "13139542237",
                "15582478171",
                "18542342887",
                "17123991743",
                "16699391656",
                "13410718970",
                "13744375582",
                "17191289258",
                "18192935670",
                "19972045773",
                "13589851355",
                "18683862564",
                "18145144830",
                "17783396956",
                "18308321257",
                "17363246404",
                "15867484945",
                "18650378415",
                "14548833228",
                "13960665007",
                "15906594658",
                "18278634616",
                "13317202544",
                "18193232168",
                "18242118160",
                "14551788103",
                "13141619031",
                "15303472472",
                "18607899610",
                "13235565148",
                "15302925795",
                "13411384157",
                "18120304474",
                "13332161071",
                "13650345263",
                "15183067688",
                "14589043550",
                "15759081376",
                "13001872229",
                "18122751046",
                "17765774689",
                "17714621353",
                "15237012814",
                "15095735297",
                "18503574099",
                "13947223279",
                "18729477212",
                "15972151716",
                "17704699143",
                "14741479379",
                "13994046736",
                "17846083134",
                "15845613318",
                "13013384809",
                "18780544257",
                "15169812047",
                "18296915936",
                "15189021132",
                "19808116900",
                "13614115466",
                "19837728853",
                "13652437409",
                "15688569797",
                "13080216720",
                "13075537042",
                "17787446250",
                "15824099216",
                "17657282758",
                "15975172945",
                "13039293940",
                "15502181194",
                "13506109057",
                "18047002678",
                "13118252809",
                "13466143786",
                "17168572276",
                "18864497794",
                "15008735069",
                "17369654990",
                "17368489404",
                "13984345386",
                "17663095386",
                "13063936430",
                "18725662389",
                "18870811648",
                "15182696630",
                "17818624056",
                "17827986434",
                "17191368053",
                "18166343245",
                "15809273473",
                "13276359149",
                "13246566055",
                "15199142409",
                "14795222706",
                "15510707552",
                "15330042533",
                "17758669221",
                "13612238252",
                "15536278554",
                "15838054898",
                "15773103343",
                "15889688958",
                "18641819448",
                "18843961977",
                "14915024675",
                "17555079669",
                "18862454772",
                "13585596435",
                "15361741254",
                "13866279967",
                "15537052220",
                "15995818734",
                "19878191303",
                "15213666527",
                "13643807250",
                "15769146322",
                "13203506192",
                "13224556299",
                "18309514862",
                "18363894524",
                "18370707724",
                "15530666085",
                "18118619840",
                "17653137575",
                "17133628888",
                "13510039210",
                "17348076277",
                "15084422979",
                "14786793333",
                "17576422007",
                "15352364714",
                "15747177000",
                "18944318146",
                "13925512749",
                "19832372359",
                "18240326195",
                "17213803910",
                "18568962832",
                "13787627362",
                "15395642054",
                "13019028966",
                "17545847965",
                "15583506027",
                "15163256117",
                "17129235996",
                "17584729624",
                "13939095761",
                "14595821718",
                "13149847027",
                "15825949231",
                "13517297419",
                "13342185759",
                "15984559990",
                "13339754356",
                "13895789885",
                "15609334568",
                "18662538576",
                "15380819087",
                "15315383987",
                "16536175405",
                "17549153286",
                "13081231161",
                "14568283930",
                "17567405850",
                "15955111089",
                "17695567951",
                "18071737828",
                "17842127994",
                "13974919478",
                "13993384186",
                "17551826467",
                "13311662251",
                "13565479531",
                "18822952543",
                "18899153677",
                "14551383879",
                "14586502859",
                "18677355807",
                "18038155450",
                "15710399168",
                "17378607605",
                "18490662243",
                "17132761669",
                "17245469361",
                "19996735767",
                "18779866145",
                "18570109327",
                "14724606118",
                "13602372731",
                "16601938813",
                "15285488770",
                "15610158806",
                "18039855838",
                "15885666095",
                "17226939152",
                "13164365037",
                "15985944195",
                "18613492683",
                "15691653572",
                "17883851527",
                "15355065394",
                "15828081845",
                "17299501359",
                "13404144077",
                "15256658127",
                "15374813159",
                "18569739667",
                "14766668589",
                "18938063429",
                "13252122111",
                "17121071193",
                "14541046158",
                "14764784087",
                "13380074719",
                "18633154853",
                "14911555018",
                "13792129177",
                "15753158324",
                "13990486675",
                "18813605874",
                "18504447845",
                "15884234690",
                "16506248760",
                "17710326369",
                "18554532968",
                "15169719833");

        SingleOutputStreamOperator  sing = dataStream.map(new MapFunction<String, Map<String, Object> >() {
            @Override
            public Map<String, Object>  map(String s) throws Exception {
                Map map = new HashMap();
                map.put("numprix", s.substring(0,3));
                map.put("value", s);
                return map;
            }
        }).process(new MyProcess());

        for (NumberOutTagEnum numberOutTagEnum:
        NumberOutTagEnum.values()) {
            outSideSink(sing,numberOutTagEnum.getName());
        }

        en.execute("sideoutput job");

    }



    private static void outSideSink(SingleOutputStreamOperator  sing ,String outag )
    {
        sing.getSideOutput(new OutputTag(outag,TypeInformation.of(String.class))).addSink(new SinkFunction() {
            @Override
            public void invoke(Object value) throws Exception {
                System.out.println("标签=="+outag+"=>"+value.toString());
            }
        }).name("支流： "+outag);

    }

}
